# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ufraw

pkgname="${MINGW_PACKAGE_PREFIX}-gimp-${_realname}"
groups=("${MINGW_PACKAGE_PREFIX}-gimp-plugins")
pkgver=0.19.2
pkgrel=1
pkgdesc="Converter for raw files; utility and GIMP plugin (mingw-w64)"
arch=('any')
url="http://ufraw.sourceforge.net/"
license=("GPL")
options=('strip' 'staticlibs')
depends=(
    "${MINGW_PACKAGE_PREFIX}-gtkimageview"
    "${MINGW_PACKAGE_PREFIX}-exiv2"
    "${MINGW_PACKAGE_PREFIX}-lcms"
    "${MINGW_PACKAGE_PREFIX}-bzip2"
    "${MINGW_PACKAGE_PREFIX}-lensfun"
    "${MINGW_PACKAGE_PREFIX}-cfitsio"
    )
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-gimp")
optdepends=("${MINGW_PACKAGE_PREFIX}-gimp: to use the gimp import plugin for raw images")
source=("http://downloads.sourceforge.net/${_realname}/${_realname}-$pkgver.tar.gz"
    mingw-getopt-long.patch
    mingw-w64-fixes.patch)
sha256sums=('73befe9f16f015a8c0f26cef3bb2e17cac9ae64aef2ade48c29aedb1ee51abd3'
            '41c7c530b6c8992653166ba2adb155c3ae137eb12ed7bc8675d623fd58a6bb13'
            'd38eb64d6b5d5d85a25e1adaa5cafbd0156ba939329b66d48c46047f833ab1ec')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/mingw-getopt-long.patch
  patch -p1 -i ${srcdir}/mingw-w64-fixes.patch
  ./autogen.sh
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  MSYS2_ARG_CONV_EXCL="GIMP_LIBDIR" \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-extras \
    --enable-mime \
    --with-gimp \
    --enable-openmp \
    --enable-contrast

  local wgimp_pref=$(cygpath -wm ${MINGW_PREFIX})
  sed -e "s|$wgimp_pref|${MINGW_PREFIX}|g" -i Makefile
  sed -e "s|-ffast-math -fomit-frame-pointer -W -Wall -O3|${CFLAGS}|" -i Makefile
  make VERBOSE=1
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make -j1 DESTDIR="$pkgdir" install
}
